from openpyxl import load_workbook

# 加载Excel
wb = load_workbook('sample2.xlsx')
# 获取工作表
ws = wb.active

# 外层循环行
for r in range(1, 10):
    # 内层循环列
    for c in range(1, r + 1):
        # print(f'{c}*{r}={r*c}',end=' ')
        ws.cell(row=r, column=c, value=f'{c}*{r}={r*c}')
    # print()
wb.save('sample2.xlsx')